﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyBanVeMayBay.Resources;

namespace QuanLyBanVeMayBay
{
    public partial class chonsan : Form
    {
        public chonsan()
        {
            InitializeComponent();
        }
        public delegate void giatritrave(string value);

        public giatritrave tensan;
        public giatritrave thoigiandung;
        public giatritrave ghichu;

        private void chonsan_Load(object sender, EventArgs e)
        {
            xulydulieu xuly = new xulydulieu();
            string sql = "select TenSanBay from SANBAY";
            cb_tensan.DataSource = xuly.taobang(sql);
            cb_tensan.DisplayMember = "TenSanBay";
        }

        private void bt_cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void bt_add_Click(object sender, EventArgs e)
        {
            if (cb_tensan.Text == "" || tb_tgdung.Text == "")
                MessageBox.Show("Chưa điền đủ thông tin", "Lỗi");
                xulydulieu xuly = new xulydulieu();
            string min = "select ThoiGianDungToiThieu from THAMSO where STT = 'True'";
            string max = "select ThoiGianDungToiDa from THAMSO where STT = 'True'";
            string mini = xuly.taobang(min).Rows[0][0].ToString();
            string maxi = xuly.taobang(max).Rows[0][0].ToString();
            if (string.Compare(tb_tgdung.Text,mini) < 0 || string.Compare(tb_tgdung.Text,maxi) > 0)
            {
                MessageBox.Show("Thời gian dừng theo quy định từ \n" + mini + " đến " + maxi, "Lỗi");
                return;
            }
            else
            {
                try
                {
                    tensan(cb_tensan.Text);
                    thoigiandung(tb_tgdung.Text);
                    ghichu(tb_ghichu.Text);
                    this.Close();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Thông tin lỗi:\n" + ex.Message, "Lỗi !");
                }
            }
        }
    }
}
